class Solution {
public:
    int a[10][10];
    int b[10][10];
    bool isValidSudoku(vector<vector<char>>& board) {
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                if (board[i][j] == '.')continue;
                int x = board[i][j] - '0';
                a[i][x]++;
                b[j][x]++;
                if (a[i][x] >= 2 || b[j][x] >= 2)return 0;
            }
        }
        int k = 1;
        int idx1 = 0;
        int idx2 = 0;
        while (k <= 9) {
            int c[10] = { 0 };
            for (int i = idx1; i <= idx1 + 2; i++) {
                for (int j = idx2; j <= idx2 + 2; j++) {
                    if (board[i][j] == '.')continue;
                    int x = board[i][j] - '0';
                    c[x]++;
                    if (c[x] >= 2)return 0;
                }
            }
            if (k % 3 == 0)idx1 += 3;
            idx2 += 3;
            idx2 %= 9;
            k++;
        }
        return 1;
    }
};